package com.licq.ldoc.parser.impl.annotation;

import java.lang.annotation.Annotation;

import net.sf.oval.constraint.Range;

import com.licq.ldoc.domain.Attribute;
import com.licq.ldoc.domain.AttributeType;
import com.licq.ldoc.parser.AnnotationParsee;

public class RangeAnnotationParsee extends AnnotationParsee {
	
	public RangeAnnotationParsee(AnnotationParsee successor) {
		super(successor);
	}

	@Override
	protected void doParse(Attribute attribute, Annotation annotation) {
		if (AttributeType.isNumberType(attribute.getType())) {
			Range range = (Range) annotation;
			StringBuffer comments = new StringBuffer();
			if (range.min() != Double.MIN_VALUE || range.max() != Double.MAX_VALUE) {
				comments.append(getText());
				if (range.min() != Double.MIN_VALUE) {
					comments.append(">=" + range.min());
				}
				if (range.max() != Double.MAX_VALUE) {
					comments.append((range.min() != Double.MIN_VALUE ? " and " : "") + "<=" + range.max());
				}
			}
			attribute.appendComments(comments.toString());
		}
	}
	
}
